/**
 * @projectName leetode
 * @package cn.leetcode
 * @className cn.leetcode.t101
 * @copyright Copyright 2020 Thunisoft, Inc All rights reserved.
 */
package cn.leetcode;

/**
 * t101
 * @description 对称二叉树
 * @author fei
 * @date 2025/9/8 17:48
 * @version 1.0
 */
public class t101 {
    public boolean isSymmetric(TreeNode root) {
        return compare(root.left, root.right);
    }
    public boolean compare(TreeNode left, TreeNode right){
        if (left == null && right == null){
            return true;
        }
        if (left != null && right == null){
            return false;
        }
        if (left==null && right != null){
            return false;
        }
        if (left.val != right.val){
            return false;
        }
        boolean out = compare(left.left, right.right);
        boolean in = compare(left.right, right.left);
        return out && in;
    }
}
